package org.vuzya.motivateme.models;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.ContentValues;
import android.database.Cursor;
import android.provider.BaseColumns;
import android.util.Log;

public class Motivations implements BaseColumns {
	public static String TABLE_NAME = "Motivations";
	public static String MOTIVATION_DATE = "MotivationDate";
	public static String BUSINESS_ID = "BusinessID";
	public static String[] SELECTION = { _ID, MOTIVATION_DATE, BUSINESS_ID };

	private static final SimpleDateFormat sdf = new SimpleDateFormat();
	
	private long id = -1;
	private Date motivationDate;
	private long businessId;
	
	public Motivations(long businessId){
		this.businessId=businessId;
		motivationDate=new Date();
	}
	
	public Motivations(Cursor cursor){
		id = cursor.getLong(cursor.getColumnIndex(_ID));
		businessId = cursor.getLong(cursor.getColumnIndex(BUSINESS_ID));
		
		String tmp = "";
		try {
			tmp = cursor.getString(cursor.getColumnIndex(MOTIVATION_DATE));
			if(tmp!=null){
				motivationDate = sdf.parse(tmp);
			}else{
				motivationDate = null;
			}
		} catch (ParseException e) {
			Log.d(TABLE_NAME, "Wrong date format: " + tmp);
		}
	}
	
	public ContentValues extractValues(){
		ContentValues cv = new ContentValues();
		if(id!=-1){
			cv.put(_ID, id);
		}
		cv.put(MOTIVATION_DATE, motivationDate.toString());
		cv.put(BUSINESS_ID, businessId);
		return cv;
	}

	public Date getMotivationDate() {
		return motivationDate;
	}
	public void setMotivationDate(Date motivationDate) {
		this.motivationDate = motivationDate;
	}
	public long getBusinessId() {
		return businessId;
	}
	public void setBusinessId(long businessId) {
		this.businessId = businessId;
	}
	public long getId() {
		return id;
	}	
}
